/**
******************************************************************************************
* @file subject.h
* @brief Design pattern Observer.
* @date 14 avril 2015
* @author Benjamin Lancinot / Ciro S. Costa
*****************************************************************************************/
/* COPYRIGHT ****************************************************************************
*****************************************************************************************
* Written By Ciro S. Costa /Adapted by Benjamin Lancinot
*
* The MIT License (MIT)
*
* Copyright (c) <2014>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
********************************************************************************************/

#ifndef SUBJECT_H
#define SUBJECT_H

/*******************************************************************************************
* INCLUSION
********************************************************************************************/

#include "observer.h"

/*******************************************************************************************
* TYPES
********************************************************************************************/

/**
 * @struct Subject
 */
typedef struct Subject
{
	int type;
	/**
	 * Destructor for the Subject
	 */
	void (*destroy)(struct Subject *);
	/**
	 * Referente to the concrete Subject object
	 */
	void * impl;
	/**
	 * A list of observes have ben are registered for this subject
	 * object.
	 */
	Observer * observers[MAX_OBSERVERS];
	/**
	 * The method that allows observers to register for this
	 * subject object.
	 */
	int (*registerObserver)(struct Subject*, Observer*);
	/**
	 * Lets observes unregister from this subject
	 */
	int (*unregisterObserver)(struct Subject *, Observer*);
	/**
	 * When fired, triggers notify method of all of the registered
	 * observers.
	 */
	void (*notifyObservers)(struct Subject*);
} Subject;

/*******************************************************************************************
* FUNCTIONS
********************************************************************************************/

/**
 * @brief Constructor
 * @param impl Pointer to object which are the subject
 * @param type Specific type of subject
 * @return The pointer to the new Subject
 **/
Subject * subjectNew(void*, int);

#endif
